package mtn.bowen.yan.server.dao;

import mtn.bowen.yan.server.model.VarietyDishes;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author <a href=mailto:yanbowen90@foxmail.com> bowen.yan </a>
 * @version 1.0
 * @description: 菜品类型种类管理表
 * @date 2021-10-23 9:31 PM
 */
@Mapper
@Repository
public interface VarietyDishesDao {

    String ID = "id";

    String TABLE_NAME = "variety_dishes";

    String ALL_FIELDS = "id,type,kind,quantity,week";

    String UNIQUE_FIELDS = "`type`, `kind`, `week`";

    String OTHER_FIELDS = "quantity";

    @Select("select " + ALL_FIELDS + " from variety_dishes ")
    List<VarietyDishes> selectAll();

    @Select("select " + ALL_FIELDS + " from variety_dishes where type = #{type} ")
    List<VarietyDishes> selectByType(@Param("type") Integer type);

    @Select("select " + ALL_FIELDS + " from variety_dishes where type = #{type} and week = #{week} ")
    List<VarietyDishes> selectByTypeAndWeek(@Param("type") Integer type, @Param("week") Integer week);


    @Insert("INSERT INTO " + TABLE_NAME + " (" + UNIQUE_FIELDS + ", " + OTHER_FIELDS + ") VALUES (#{type}, #{kind}, #{week}, #{quantity})" + " ON DUPLICATE KEY UPDATE `type`=#{type}, `kind`=#{kind}, `week`=#{week}, `quantity`=#{quantity}")
    @Options(useGeneratedKeys = true, keyColumn = ID)
    int insertOnUpdate(VarietyDishes varietyDishes);
}
